<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Hello, This is user service.</title>
</head>
<body>
<h2>User - Cross Domain - Embedded iFrame</h2>
<p>This is an embedded iframe, which will communicate with parent windows by postMessage.</p>

<div>
    <div>message from parent windows:</div>
    <ol id="message_recv"></ol>
</div>

</body>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript">

    // receive message from parent window, and save message to local storage
    window.addEventListener('message', function (msg) {
        if (msg.source != window.parent)
            return;

        localStorage.setItem('message', msg.data);
        $("#message_recv").append("<li>" + msg.data + "</li>");
        window.parent.postMessage('消息已保存到http://localhost:9001的local storage中: ' + msg.data, '*');

        alert("消息已保存到http://localhost:9001的local storage中。请打开页面并按F12检查。");
    }, false);


</script>
</html>